package com.squirrel.michale;

import java.util.Arrays;

/**
 * @author guanhao 观浩
 * @version 1.0.0.0
 * @createTime 2023/3/9 8:59 PM
 * @company Michale Squirrel
 * @link
 * @description
 */
public class LeetCode0949 {


    public String largestTimeFromDigits(int[] arr) {

//        int n = arr.length;
//        for (int i = 0; i < n; i++) {
//
//        }
        return "";

    }


    public String largestTimeFromDigits2(int[] arr) {
        StringBuilder sb = new StringBuilder();
        int sum = 0;
        int max = -1;
        int temp = 0;
        boolean mark = true;
        for(int i = 0;i<4;i++) {
            for (int j = 0; j < 4; j++) {
                for (int k = 0; k < 4; k++) {
                    for (int l = 0; l < 4; l++) {
                        if (i != j && i != k && i != l && j != k && j != l && k != l) {
                            sum = arr[l] * 1000 + arr[k] * 100 + arr[j] * 10 + arr[i];
                            temp = arr[j] * 10 + arr[i];
                            if (sum <= 2359 && sum > max && temp < 60) {
                                max = sum;
                                mark = false;
                            }
                        }
                    }
                }
            }
        }
        if(mark) {
            return "";
        } else {
            sb.append((max/1000)+"");
            max =max%1000;
            sb.append((max/100)+"");
            sb.append(":");
            max = max%100;
            sb.append((max/10)+"");
            max = max%10;
            sb.append(max+"");

        }
        return sb.toString();
    }


    public String largestTimeFromDigits3(int[] arr) {
        Arrays.sort(arr);
        for(int i=3; i>=0; i--){
            if(arr[i]>2) continue;
            for(int j=3; j>=0; j--) {
                if (j==i || arr[i]==2 && arr[j]>3) continue;
                for (int k=3; k>=0; k--) {
                    if (k==i || k==j || arr[k]>5) continue;
                    return "" + arr[i] + arr[j] + ':' + arr[k] + arr[6-i-j-k];
                }
            }
        }
        return "";
    }
}
